package com.jojo.jojomall.search.Mythread;

import java.util.concurrent.*;

/**
 * @Author: 魔法少女小夫
 * @Data: 2022/5/20
 * @Version:
 * @Description:
 */
public class manyTaskTest {
    public static final ExecutorService excutor = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main--------stat------");
        CompletableFuture<String> futureImg = CompletableFuture.supplyAsync(() -> {
            System.out.println("正在查询图片");
            return "猫猫.jpg";
        });
        CompletableFuture<String> futureAttr = CompletableFuture.supplyAsync(() -> {
            System.out.println("正在搜索属性");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "西瓜头";
        });
        CompletableFuture<String> futureValue = CompletableFuture.supplyAsync(() -> {
            System.out.println("正在查询图片内容");
            return "惊奇回头";
        });
//        执行allof可以让所有的线程 get执行完以后再 全部收集到返回信息
//        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.allOf(futureImg, futureAttr, futureValue);
//        voidCompletableFuture.get();
        /*执行anyof*/
        CompletableFuture<Object> anyOf = CompletableFuture.anyOf(futureImg, futureAttr, futureValue);
        System.out.println(anyOf.get());

//        System.out.println("main--------end------"+futureImg.get()+"->"+futureAttr.get()+"->"+futureValue.get());
        System.out.println("main---------end---------");
    }
}
